package com.dspsemi.wodi.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dspsemi.wodi.R;
import com.dspsemi.wodi.entity.Chat;

public class ChatListAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private ArrayList<Chat> list;
	private Context c;

	public ChatListAdapter(Context context, ArrayList<Chat> it) {
		mInflater = LayoutInflater.from(context);
		c = context;
		list = it;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_chat_listview, null);
			holder = new ViewHolder();

			holder.content = (TextView) convertView.findViewById(R.id.content);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.content.setText(list.get(position).getName() + "说："
				+ list.get(position).getContent());

		return convertView;
	}

	private class ViewHolder {
		public TextView content;

	}

}
